var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), a = require("../../../@babel/runtime/helpers/asyncToGenerator"), e = getApp();

Page({
    data: {
        language: "",
        isclick: !0,
        order_id: "",
        store_id: "",
        orderData: null,
        balance: 0,
        payParams: "",
        info_form: {},
        order_sn: "",
        money: "",
        buttons: [],
        pay_sn: "订单编号",
        order_pay_id: "",
        uid: "",
        pid: "",
        status: "",
        showPacket: !1,
        redirectData: {},
        cbHref: {},
        is_cps: !1,
        senceKey: "",
        popupSpecs: !1,
        payarr: ""
    },
    onLoad: function(t) {
        this.data.options = t, wx.setNavigationBarTitle({
            title: "订单支付"
        });
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        }), this.getData();
    },
    getData: function() {
        var t = this, a = e.getNetAddresss("plugin.crowdfunding.frontend.pre-activity-order.detail");
        e._getNetWork({
            url: a,
            data: {
                order_sn: this.data.options.sn
            },
            success: function(a) {
                var n = a.data;
                1 == n.result ? (t.setData({
                    order_sn: n.data.order_sn,
                    money: n.data.amount,
                    buttons: n.data.buttons
                }), t.data.buttons[0] && t.setData({
                    radio: t.data.buttons[0].value
                })) : e.tips(n.msg);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    refChange: function(t) {
        for (var a in this.data.buttons) if (this.data.buttons[a].value == t) return this.data.buttons[a];
    },
    payKeyboardClose: function() {
        this.setData({
            payarr: "",
            popupSpecs: !1
        });
    },
    payKeyboardComplete: function(t) {
        console.log(t, "dddddddddd"), this.getVerifyPassword(t.detail);
    },
    getVerifyPassword: function(t) {
        var a = this, n = e.getNetAddresss("payment.password.check");
        n += "&password=" + t, e._getNetWork({
            url: n,
            success: function(e) {
                var n = e.data;
                1 == n.result ? (a.setData({
                    payarr: t
                }), a.confirm()) : (a.setData({
                    payarr: ""
                }), wx.showModal({
                    title: "提示",
                    content: n.msg,
                    success: function(t) {
                        t.confirm ? 2001 == n.data.code || (2002 == n.data.code ? wx.navigateTo({
                            url: "/packageA/member/set_balance_password/set_balance_password"
                        }) : n.data.code) : t.cancel && (2001 == n.data.code || 2002 == n.data.code || n.data.code);
                    }
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    confirm: function() {
        var n = this;
        return a(t.default.mark(function a() {
            var o;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    if (!n.data.radio || n.data.payarr) {
                        t.next = 7;
                        break;
                    }
                    return t.next = 3, n.refChange(n.data.radio);

                  case 3:
                    if (!t.sent.need_password) {
                        t.next = 7;
                        break;
                    }
                    return n.setData({
                        popupSpecs: !0
                    }), t.abrupt("return");

                  case 7:
                    o = e.getNetAddresss("plugin.crowdfunding.frontend.activity-order.pay"), e._getNetWork({
                        url: o,
                        data: {
                            order_sn: n.data.options.sn,
                            amount: n.data.money,
                            pay_type_id: n.data.radio
                        },
                        success: function(t) {
                            var a = t.data;
                            1 == a.result ? a.data.config ? n.WXPay_other(a.data.config) : (n.data.isclick = !1, 
                            e.tips(a.msg), wx.showToast({
                                title: a.msg,
                                duration: 1e3,
                                icon: "none",
                                success: function(t) {
                                    setTimeout(function() {
                                        wx.redirectTo({
                                            url: "/packageF/crowd_activity/index/index"
                                        });
                                    }, 1e3);
                                }
                            })) : e.tips(a.msg);
                        },
                        fail: function(t) {
                            console.log(t);
                        }
                    });

                  case 9:
                  case "end":
                    return t.stop();
                }
            }, a);
        }))();
    },
    WXPay_other: function(t) {
        wx.requestPayment({
            timeStamp: t.timestamp,
            nonceStr: t.nonceStr,
            package: t.package,
            signType: t.signType ? t.signType : "MD5",
            paySign: t.paySign,
            success: function(t) {
                wx.showModal({
                    title: "提示",
                    content: "支付成功",
                    showCancel: !1,
                    success: function(t) {
                        t.confirm && wx.redirectTo({
                            url: "/packageF/crowd_activity/index/index"
                        });
                    }
                });
            },
            fail: function(t) {
                console.log(t), wx.showToast({
                    title: "支付失败请稍后重试",
                    icon: "none",
                    duration: 2e3
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});